<?php
			ob_start();			
?>
<?php
		
		if (isset($_COOKIE["user"])) {
			// if cookie <> ""
		  }
		  else
		  {
			   header("location:login.php");
			  
		  }
?>
<?php
                    if(isset($_POST["btnsubmit"]))
                    {
						$cat_id=$_POST["txtid"];
						$category=$_POST["txtcategory"];
						$public=$_POST["cbopublic"];
						$order=$_POST["txtorder"];
      					
						$fieldimage = "";
						$oldfilename = $_POST["txtoldimage"];
						$newfilename = escapeValue($_FILES["uploadfile"]["name"]);
						
						/*$sql = "UPDATE tbl_category SET  cat_name='$category'
						, public='$public', orders='$order' WHERE cat_id={$cat_id}";
							if(query($sql))
							{
								errorMessage("Mettez à jour réussies!");
							}	
							else
							{
								errorMessage("Mettre à jour échoue ..!");
							}	*/
						if($newfilename=="")
						{
							if(@$errors == "")
										{
											$sql = "UPDATE tbl_category SET  cat_name='$category'
													, public='$public', orders='$order' WHERE cat_id={$cat_id}";													
											if(query($sql))
											{
													errorMessage("Mise à jour réussie ...!");
													
													//direct to itself and get pro_id=ocure pro_id
													//pageRedirect("productEdit.php?pro_id=$pro_id","");
											}
										}
						}//  $newfilename =""
						else
						{
							if(@$errors == "")
								{
										//Upload Image
										$image_name = $_FILES["uploadfile"]["name"];
										$image_tmp_name = $_FILES["uploadfile"]["tmp_name"];
										$ext = "jpg";	
										$tag = "";
										$path = "category";
										
										// cate photo		
										$width = 184;
										$height = 211;			
										createImageAndThumb($image_tmp_name,$image_name,
															$width,
															$height,
															$tag,
															$path,
															$image_name);
										//end upload image
										if(@$errors == "")
										{
											$sql = "UPDATE tbl_category SET  cat_name='$category'
													, public='$public', orders='$order', photo='$newfilename' WHERE cat_id={$cat_id}";												
											if(query($sql))
											{
													deleteFile("category/{$oldfilename}");
													errorMessage("Mise à jour réussie ...!");
											}
										}				
								}//end check error=""
								
						}//end else $newfilename != ""	
                    } 
                ?>
<?php
	if(isset($_REQUEST["cat_id"]))
	{
	@$cat_id=$_REQUEST["cat_id"];
	$sql="SELECT * FROM tbl_category WHERE cat_id=$cat_id";
	$result=query($sql);
	$row=mysql_fetch_array($result);
	
	$cat_id=$row["cat_id"];
	$category=$row["cat_name"];
	$public=$row["public"];
	$orders=$row["orders"];
	$uploadfile = $row["photo"];
	}
	
?>

                	<div id="border_cont_title">
                        	<div id='content_title_left'>catégorie Edition</div>
                            <div id='content_title_right'></div>
					</div> <!--end border_cont_title-->
                    <?php echo @$errors;?>
                    	 <!--start table -->
                    <form action="index.php?page=categoryEdit" method="post" enctype="multipart/form-data">
                    	<table width="775px">
                        	<tr>
                            	<td bgcolor="#FFEAD7">Catégorie</td>
                                <td>
                                	<input type="hidden" name="txtid" value="<?php echo @$cat_id;?>" size="40" />
                               
                                	<input type="text" name="txtcategory" value="<?php echo @$category;?>" size="40" />
                                </td>
                                
                            </tr>
                            <tr>
                            	<td bgcolor="#FFEAD7">Public</td>
                                <td>
                                	<select name="cbopublic" >
                                    	<?php
											if(@$public=="1")
											{
												echo "<option value=".@$public." selected='selected'>yes</option>";
                                        		echo "<option value='0'>no</option>";
											}
											elseif(@$public=="0")
											{
												echo "<option value='1'>yes</option>";
                                        		echo "<option value=".@$public." selected='selected'>no</option>";
											}
											
                                        ?>
                                    	
                                    </select>
                                </td>
                            </tr>
                            <tr>
                            	<td bgcolor="#FFEAD7">Ordre</td>
                                <td><input type="text" name="txtorder" value="<?php echo @$orders; ?>" size="5" /></td>
                            </tr>
                            <tr>
                            	<td align="left" height="30" bgcolor="#FFEAD7">Photo</td>
                                 <td>
                                <input class="submit" type="file" name="uploadfile" /><img src="category/<?php echo @$uploadfile ;?>" width="80px" height="70px" />
                                <input type="hidden" value="<?php echo @$uploadfile; ?>" name="txtoldimage" />
                                 </td>
                            </tr>
                            <tr>
                            	<td bgcolor="#FFEAD7">Action</td>
                                <td>
                                
                                <input class="submit" type="submit" name="btnsubmit" value="Soumettre"  />
                                <input class="submit" type="button" name="btncancel" value="Annuler" onclick="redirect('index.php?page=category')" />
                                
                                </td>
                                
                            </tr>
                        </table>
                        </form>
                    <!--end table -->
                    